<?php
    cria_variaveis($_POST,$_GET,$_FILES);
?> 
<p class=titulo align=center><?php echo $msg->get('EQNL_MSG_02') ?></p>
<p class=subtitulo align=center><?php echo $msg->get('EQNL_MSG_03b') ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=eqnl2.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=eqnl2.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=eqnl2.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
    if (!isset($Calcular)) {
        if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
        {
            require_once("./classes/upload.php");
            $uploads = new Upload();
            $uploads->Lista("reseqnl");
        }
        else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo" && !isset($opcao_execucao)) {
            include "exibe_prob_eqnl2_xml.php";
        }
        else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado" || isset($opcao_execucao)) {
            if (strlen($opcao_execucao) == 0) {
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<p>".$msg->get('EQNL_MSG_41')."<br><br>";
                echo "<input type=radio name=opcao_execucao value=0> ".$msg->get('EQNL_MSG_42')."<br>";
                echo "<input type=radio name=opcao_execucao value=1> ".$msg->get('EQNL_MSG_43')."<br><br>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            }
            else if (($opcao_execucao == 0)and (($deg == NULL) || !checaNumerico($deg)) ) {
                //entrar com o valor do grau do polinomio no caso polinomial
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<p>".$msg->get('EQNL_MSG_04')."<br>";
                echo "<input type=text size='2' maxlength='2' name=deg value=".$deg."><br><br>";
                echo "<input type=hidden name=opcao_execucao value=0>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            }
            else if ( ($opcao_execucao == 0 && !checaNumerico($coef)) || ($opcao_execucao == 1 && $funcao == NULL) || !checaNumerico($error) || !checaNumerico($it)) {               //entrar com os coeficientes do polinomio/funcao de entrada e erro relativo e numero de iteracoes
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                if ($opcao_execucao == 0) {
                    //para caso polinomial
                    echo "<p>".$msg->get('EQNL_MSG_05')."<br>";
                    echo "f(x)=";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=text size=5 maxlength=5 name=coef[".$i."] value=".$coef[$i]."> x <sup>".($deg-$i)."</sup>+";
                    } // end for
                    echo "<input type=text size=5 maxlength=5 name=coef[".$deg."] value=".$coef[$deg]."><br><br>";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } //end if
                else if ($opcao_execucao == 1) {
                    //para caso geral
                    echo "<a href=javascript:winopen('ajuda/funcoesphp.php')>".$msg->get('G_MSG_29')."</a>";
                    echo "<p>";
                    echo $msg->get('EQNL_MSG_40')."<br><br>";
                    echo "f(x)= <input type=text size=60 maxlength=100 name=funcao value=".$funcao."><br>";
                    echo "<br>";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if
                echo "".$msg->get('EQNL_MSG_06')."<br>";
                echo "<input type=text size=9 maxlength=9 name=error value=".$error."><br><br>";
                echo "".$msg->get('EQNL_MSG_07')."<br>";
                echo "<input type=text size=3 maxlength=3 name=it value=".$it."><br><br>";
                echo "<input type=hidden name=deg value=".$deg.">";
                echo "<input type=hidden name=d value=1>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            } else {
                if ((!isset($_POST['Plotar']) && !isset($_POST['Calcular'])) || !checaNumerico($graphx1) || !checaNumerico($graphx2))
                {
                echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<p>";
                if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                    verificaBib($xml_file);
                echo "<br>";
                echo $msg->get('EQNL_MSG_08')."<br>";
                echo "f(x)=";
                if ($opcao_execucao == 0) { //imprimir funcao polinomial
                    for($i = 0; $i < $deg; $i++) {
                        echo $coef[$i]."x<sup>".($deg-$i)."</sup>";
                        if ($coef[$i+1] >= 0)
                            echo "+";
                    }
                    echo($coef[$deg])."<br>".$msg->get('EQNL_MSG_09')." ".($deg)." <br>";
                } // end if opcao_execucao
                else if ($opcao_execucao == 1) { //imprimir funcao qualquer
                    echo $funcao."<br>";
                } // end if opcao_execucao
                echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
                echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
                //cria a tabela de enumeracao de razoes do polinomio - **Caso polinomial**
                if ($opcao_execucao == 0) {
                    $tabela = enumera_raizes($coef, $deg);
                    echo "<table border=0 width=600 cellspacing=1 cellpadding=2 bgcolor=\"#000000\">";
                    echo "   <th colspan=4 align=center bgcolor=\"#ffffff\">";
                    echo "      ".$msg->get('EQNL_MSG_12')."";
                    echo "   </th>";
                    echo "   <tr>";
                    echo "       <td bgcolor=\"#ffffff\" align=center> <b>".$msg->get('EQNL_MSG_13')."</b> </td>";
                    echo "       <td bgcolor=\"#ffffff\" align=center> <b>".$msg->get('EQNL_MSG_14')."</b> </td>";
                    echo "       <td bgcolor=\"#ffffff\" align=center> <b>".$msg->get('EQNL_MSG_15')."</b> </td>";
                    echo "       <td bgcolor=\"#ffffff\" align=center> <b>".$msg->get('EQNL_MSG_16')."</b> </td>";
                    echo "   </tr>";
                    for ($i = 1; $i <= $tabela[0]["positiva"]; $i++) {
                        echo "<tr>";
                        echo "<td bgcolor=\"#ffffff\" align=center>".($tabela[$i]["positiva"])."</td>";
                        echo "<td bgcolor=\"#ffffff\" align=center>".($tabela[$i]["negativa"])."</td>";
                        echo "<td bgcolor=\"#ffffff\" align=center>".($tabela[$i]["complexa"])."</td>";
                        echo "<td bgcolor=\"#ffffff\" align=center>";
                        $total = $tabela[$i]["positiva"] + $tabela[$i]["negativa"] + $tabela[$i]["complexa"];
                        echo ($total)."</td>";
                        echo "</tr>";
                    } // end for
                    echo "</table><br>";
                    // define as cotas superior e inferior **Caso polinomial** (Cota de Laguerre-Thibault)
                    //cota (localizacao das raizes)
                    $absmax = abs($coef[$deg]);
                    for ($i = $deg; $i > 0; $i--) {
                        if (abs($coef[$i]) > $absmax)
                            $absmax = abs($coef[$i]);
                    }
                    $cotacalc = 1 + ((1 / abs($coef[0]) ) * $absmax);
                    $cota_superior = $cotacalc;
                    $cota_inferior = -1 * $cotacalc;
                    echo "<table border=0 width=600 cellspacing=1 bgcolor=\"#000000\" cellpadding=2>";
                    echo "   <th colspan=2 bgcolor=\"#ffffff\" align=center>".$msg->get('EQNL_MSG_17')."</th>";
                    echo "   <tr>";
                    echo "    <td bgcolor=\"#ffffff\" align=center><b>".$msg->get('EQNL_MSG_18')."</b></td>";
                    echo "    <td bgcolor=\"#ffffff\" align=center><b>".$msg->get('EQNL_MSG_19')."</b></td>";
                    echo "   </tr>";
                    echo "   <tr>";
                    echo "    <td bgcolor=\"#ffffff\" align=center>".($cota_inferior)."</td>";
                    echo "    <td bgcolor=\"#ffffff\" align=center>".($cota_superior)."</td>";
                    echo "   </tr>";
                    echo "</table>";
                } // end if opcao == 0 (polinomial)
                echo "<br>".$msg->get('Intervalo_Para_Plotar').": <br>";
                echo "<p><font size=4>";
                echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
                echo "<input type=hidden name=int1 value=".@$int1.">";
                echo "<input type=hidden name=int2 value=".@$int2.">";
                echo "</font>";
                echo "<input type=hidden name=mudagrafico value=sim>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input type=hidden name=it value=".$it.">";
                echo "<input type=hidden name=error value=".$error.">";
                if ($opcao_execucao == 0) {
                    echo "<input type=hidden name=deg value=".$deg.">";
                    echo "<input type=hidden name=d value=".@$d.">";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=hidden name=coef[] value=".$coef[$i].">";
                    }
                    echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } // end if opcao_execucao == 0
                if ($opcao_execucao == 1) {
                    echo "<input type=hidden name=funcao value=".$funcao.">";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if opcao_execucao == 1
                echo "<p><p>";
                echo "<p>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                    echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
                }
                echo "<input type=\"hidden\" name=\"metodo\" value=\"bisseccao\">";
                //echo "<input class=button type=\"button\" name=\"Submit\" value=".(EQNL_MSG_25)."onClick=\"enviar()\"><br><br>";
                if (isset($_POST["respeqnl1"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
                }
                if (isset($_POST["respeqnl3"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
                }
                echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
                echo "<br>";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                    echo "function criarLinks(value) {\n";
                    echo "document.exemplos.indice.value = value;\n";
                    echo "document.exemplos.action = 'index.php?inc=eqnl2.php&modo=exemplo'\n";
                    echo "document.exemplos.submit();\n";
                    echo "}\n";
                    echo "</script>";
                    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\">";
                    echo "</form>";
                    echo $msg->get('Outros_Exemplos').":<br>";
                    $objeto = new DOMDocument();
                    $objeto->load($xml_file);
                    $filho = $objeto->getelementsbytagname("rootfinding");
                    if ($filho->length > 0)
                    {
                        $tmp=0;
                        $equation = $filho->item(0)->getelementsbytagname("equation");
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'polynom')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'function')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                    }
                }
            } //end if (!isset($_POST['Plotar']))
            else {
                echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<p>";
                if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                    verificaBib($xml_file);
                echo "<br>";
                echo $msg->get('EQNL_MSG_08')."<br>";
                echo "f(x)=";
                if ($opcao_execucao == 0) { //imprimir funcao polinomial
                    for($i = 0; $i < $deg; $i++) {
                        echo $coef[$i]."x<sup>".($deg-$i)."</sup>";
                        if ($coef[$i+1] >= 0)
                            echo "+";
                    }
                    echo($coef[$deg])."<br>".$msg->get('EQNL_MSG_09')." ".($deg)." <br>";
                } // end if opcao_execucao
                else if ($opcao_execucao == 1) { //imprimir funcao qualquer
                    echo $funcao."<br>";
                } // end if opcao_execucao
                echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
                echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
                $dados_grafico = "$opcao_execucao|";
                if ($opcao_execucao == 0) {
                    $dados_grafico .= "$deg|";
                        for ($i=0;$i<=$deg;$i++) { $dados_grafico .= "$coef[$i]|" ;}
                } // end if
                if ($opcao_execucao == 1) {
                    $aux = normaliza_funcao($funcao);
                    $dados_grafico .= "$aux|";
                } // end if
                $dados_grafico .= "$graphx1|";
                $dados_grafico .= "$graphx2|";
                $arquivo = gera_nome_arquivo();
                $conn = &ADONewConnection($A_DB_TYPE);
                $conn->PConnect($A_DB_HOST,$A_DB_USER,$A_DB_PASS,$A_DB_DB);
                $sql = "INSERT INTO grafico(id,dados) values ('".$arquivo."','".$dados_grafico."');";
                $rs = $conn->Execute($sql);
                if ($rs === false) die(A_LANG_LOGIN_MSG5);
                $rs->Close();
                echo "<br>";
                echo "<table>";
                echo "<tr>";
                echo "<td><img src=eqnl_grafico.php?arquivo=".$arquivo."  border=0 align=center width=600 height= 400></td>";
                echo "</table>";
                echo "<br><br>";

                echo "<br>".$msg->get('Intervalo_Busca')."<br>";
                echo "<p><font size=4>";
                echo "[<input type=text size=5 maxlength=5 name=int1 value=".@$int1."> ; <input type=text size=5 maxlength=5 name=int2 value=".@$int2."> ]<br><br>";
                echo "</font>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input type=hidden name=it value=".$it.">";
                echo "<input type=hidden name=error value=".$error.">";
                echo "<input type=hidden name=graphx1 value=$graphx1>";
                echo "<input type=hidden name=graphx2 value=$graphx2>";
                if ($opcao_execucao == 0) {
                    echo "<input type=hidden name=deg value=".$deg.">";
                    echo "<input type=hidden name=d value=".@$d.">";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=hidden name=coef[] value=".$coef[$i].">";
                    }
                    echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } // end if opcao_execucao == 0
                if ($opcao_execucao == 1) {
                    echo "<input type=hidden name=funcao value=".$funcao.">";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if opcao_execucao == 1
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                    echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
                }
                echo "<input type=\"hidden\" name=\"metodo\" value=\"bisseccao\">";
                //echo "<input class=button type=\"button\" name=\"Submit\" value=".(EQNL_MSG_25)."onClick=\"enviar()\"><br><br>";
                if (isset($_POST["respeqnl1"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
                }
                if (isset($_POST["respeqnl3"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
                }
                echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
                if (isset($_POST['mudagrafico']))
                {
                    echo "<br><br><br>".$msg->get('Plotar_Outro_Intervalo').":<br>";
                    echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
                    echo "<input type=hidden name=mudagrafico value=sim>";
                    echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
                }
                echo "<br>";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                    echo "function criarLinks(value) {\n";
                    echo "document.exemplos.indice.value = value;\n";
                    echo "document.exemplos.action = 'index.php?inc=eqnl2.php&exemplo'\n";
                    echo "document.exemplos.submit();\n";
                    echo "}\n";
                    echo "</script>";
                    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\">";
                    echo "</form>";
                    echo "Outros exemplos:<br>";
                    $objeto = new DOMDocument();
                    $objeto->load($xml_file);
                    $filho = $objeto->getelementsbytagname("rootfinding");
                    if ($filho->length > 0)
                    {
                        $tmp=0;
                        $equation = $filho->item(0)->getelementsbytagname("equation");
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'polynom')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'function')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                    }
                }

            }
            echo "</body>";
            }
        }
    } else {
        if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
            verificaBib($xml_file);
        echo $msg->get('EQNL_MSG_08')."<br>\n";
        echo "f(x)=";
        if ($opcao_execucao == 0) {
            //imprimir funcao polinomial
            for($i = 0; $i < $deg; $i++) {
                echo($coef[$i]);
                echo("x<sup>");
                echo($deg-$i);
                echo("</sup>");
                if ($coef[$i+1] >= 0) {
                    echo "+";
                }
            }
            echo($coef[$deg]);
            echo "<br>";
            echo $msg->get('EQNL_MSG_09')."".($deg)."<br>\n";
        } // end if opcao_execucao
        else if ($opcao_execucao == 1) {
            //imprimir funcao qualquer
            echo $funcao;
            echo "<br>\n";
        } // end if opcao_execucao
        echo $msg->get('EQNL_MSG_10')."" .($error)."<br>\n";
        echo $msg->get('EQNL_MSG_11')."".($it)."<br>\n";
        echo $msg->get('EQNL_MSG_26b')." [".($int1).";".($int2)."]<br><br>\n";
        echo "<table border=1 width=30% cellspacing=0>\n";
        echo "   <tr>\n";
        echo "    <td>\n";
        echo "      <p align=center> <b>".$msg->get('EQNL_MSG_27')."</b> </p>\n";
        echo "    </td>\n";
        echo "    <td>\n";
        echo "      <p align=center> <b> x </b> </p>\n";
        echo "    </td>\n";
        echo "    <td>\n";
        echo "      <p align=center> <b> f(x) </b> </p>\n";
        echo "    </td>\n";
        echo "    <td>";
        echo "      <p align=\"center\"><b>".$msg->get('EQNL_MSG_10')."</b></p>";
        echo "    </td>";
        echo "   </tr>\n";
        $j = 1;
        $stop = false;
        $volta = false;
        $ok = false;
        //while($ok!=true){
        if ($opcao_execucao == 0) {
            $fmin = Resolve($coef, $deg, $int1);
            $fmax = Resolve($coef, $deg, $int2);
        } elseif ($opcao_execucao == 1) {
            $faux = normaliza_funcao($funcao).";";
            $x = $int1;
            eval ('$fmin='.$faux);
            $x = $int2;
            eval ('$fmax='.$faux);
        }
        // verifica se  as extremidades nao sao solucao da funcao
        if (abs($fmin) <= $error) {
            echo "</table>";
            echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
            echo $msg->get('EQNL_MSG_22')."".$int1."".$msg->get('EQNL_MSG_23')."0".$msg->get('EQNL_MSG_24');
            echo " f(".$int1.") = ".$fmin."";
        }
        else if (abs($fmax) <= $error) {
            echo "</table>";
            echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
            echo $msg->get('EQNL_MSG_22')."".$int2."".$msg->get('EQNL_MSG_23')."0".$msg->get('EQNL_MSG_24');
            echo " f(".$int2.") = ".$fmax."";
        }
        else if(($fmin * $fmax) > 0) {
            echo "</table>";
            echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
            echo $msg->get('EQNL_MSG_36');
            $volta = true;
        } else {
            $ok = true;
        }
        //}
        if ($ok == true) {
            $min = $int1;
            $max = $int2;
            while (($j < $it) && ($stop != true)) {
                $xmedio = ($min+$max)/2;
                if ($opcao_execucao == 0) {
                    $fmedio[$j] = Resolve($coef, $deg, $xmedio);
                }
                else if ($opcao_execucao == 1) {
                    $x = $xmedio;
                    eval ('$fmedio[$j]='.$faux);
                }
                // imprimir as iteracoes na tela
                if ($j != 1) {
                    echo "   <tr>\n";
                    echo "    <td>\n";
                    echo "      <p align=center>" .($j-1). "</p>\n";
                    echo "    </td>\n";
                    echo "    <td>\n";
                    echo "      <p align=center>" .($xmedio). "</p>\n";
                    echo "    </td>\n";
                    echo "    <td>\n";
                    echo "      <p align=center>" .($fmedio[$j]). "</p>\n";
                    echo "    </td>\n";
                    echo "    <td> ".(abs($xanterior-$xmedio)/abs($xmedio))."</td>";
                    //else echo "<td>-</td>";
                    echo "   </tr>\n";
                }
                // criterio de parada
                // se o zero for exato
                if ($fmedio[$j] == 0) {
                    echo "</table>\n";
                    echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>\n";
                    echo $msg->get('EQNL_MSG_29')."".$xmedio;
                    $stop = true;
                    if ($opcao_execucao == 0) verifica_polino($coef, $deg, $xmedio);
                        elseif ($opcao_execucao == 1) verifica_funcao($funcao, $xmedio);
                    $encontrouresp = true;
                    $respencontrada = $xmedio;
                    $respiteracoes = $j;
                    if (isset($_POST["respeqnl1"]) && isset($_POST["respeqnl3"]))
                    {
                        //echo $_POST["itereqnl1"]."/".$_POST["itereqnl2"]."/".$j;
                        if ($opcao_execucao==0) quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$xmedio,$j,$_POST["respeqnl3"],$_POST["itereqnl3"],0,$coef,$deg);
                        else  quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$xmedio,$j,$_POST["respeqnl3"],$_POST["itereqnl3"],1,$funcao);
                    }
                } else {
                    // senao calcula o erro relativo
                    if ($j != 0) {
                        if ($xmedio != 0) $erro_relativo = (abs($xanterior-$xmedio)/abs($xmedio));
                        else $erro_relativo = $error;
                    }
                    if (($erro_relativo < $error) && ($fmedio[$j] < $error)) {
                    //if () {
                        echo "</table>\n";
                        echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>\n";
                        echo $msg->get('EQNL_MSG_22')."".$xmedio."".$msg->get('EQNL_MSG_23')."".($j)."".$msg->get('EQNL_MSG_24');
                        $stop = true;
                        $encontrouresp = true;
                        $respencontrada = $xmedio;
                        $respiteracoes = $j;
                        if ($opcao_execucao == 0) verifica_polino($coef, $deg, $xmedio);
                        elseif ($opcao_execucao == 1) verifica_funcao($funcao, $xmedio);
                        if (isset($_POST["respeqnl1"]) && isset($_POST["respeqnl3"]))
                        {
                            echo $_POST["itereqnl1"]."/".$_POST["itereqnl2"]."/".$j;
                            if ($opcao_execucao==0) quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$xmedio,$j,$_POST["respeqnl3"],$_POST["itereqnl3"],0,$coef,$deg);
                            else  quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$xmedio,$j,$_POST["respeqnl3"],$_POST["itereqnl3"],1,$funcao);
                        }
                    }
                } // end else
                /*    if((($xmedio-$min)<$error)&&(($max-$xmedio)<$error)){
                echo "</table>";
                echo "<br><b>".EQNL_MSG_28."</b><br>";
                echo EQNL_MSG_22."".$xmedio."".EQNL_MSG_23."".($j)."".EQNL_MSG_24;
                $stop=true;
                }
                */    if ($stop!=true){
                $xanterior = $xmedio;
                if (($fmedio[$j] * $fmin) < 0) {
                    $max = $xmedio;
                    $fmax = $fmedio[$j];
                    $j++;
                } else {
                    $min = $xmedio;
                    $fmin = $fmedio[$j];
                    $j++;
                }
            }
        } //end while
        if ($j >= $it) {
            echo "</table>";
            echo "<br> <b>".$msg->get('EQNL_MSG_28')."</b> <br>";
            $msg = $msg->get('EQNL_MSG_32')."".($j-1)."".$msg->get('EQNL_MSG_33')."<br>";
            echo $msg;
        }
    } //end if ok
    echo "<br>";
    echo "\n<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>\n";
    if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
        echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">\n";
        echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">\n";
        echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">\n";
    }
    if (isset($_POST["respeqnl1"])) {
        echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">\n";
    }
    if (isset($_POST["respeqnl3"])) {
        echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">\n";
    }
    echo "<input type=hidden name=executar value=sim>\n";
    echo "<input type=hidden name=resp value=".@$resp.">\n";
    echo "<input type=hidden name=correcao value=".@$correcao.">\n";
    echo "<input type=hidden name=resp_it value=".@$resp_it.">\n";
    echo "<input type=hidden name=it value=".@$it.">\n";
    echo "<input type=hidden name=error value=".@$error.">\n";
    if ($opcao_execucao == 0) {
        echo "<input type=hidden name=deg value=".$deg.">\n";
        echo "<input type=hidden name=d value=".$d.">\n";
        for($i = 0; $i < $deg; $i++) {
            echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">\n";
        }
        echo "<input type=hidden name=coef[] value=".$coef[$deg].">\n";
        echo "<input type=hidden name=opcao_execucao value=0>\n";
    } // end if
    if ($opcao_execucao == 1) {
        echo "<input type=hidden name=funcao value=".$funcao.">\n";
        echo "<input type=hidden name=opcao_execucao value=1>\n";
    } // end if
    echo "<input type=hidden name=graphx1 value=".@$graphx1.">";
    echo "<input type=hidden name=graphx2 value=".@$graphx2.">";
    echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_35').">\n";
    echo "</form>\n";
    echo "<p>";
    echo $msg->get('G_PROXIMO_EXEMPLO')."<p>";
    // formulario para Metodo da Bisseccao
    echo "\n<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>\n";
    if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
        echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">\n";
        echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">\n";
        echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">\n";
    }
    if (isset($encontrouresp) && $encontrouresp == true) {
        echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"$respencontrada\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"$respiteracoes\">\n";
    }
    if (isset($_POST["respeqnl1"])) {
        echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">\n";
    }
    if (isset($_POST["respeqnl3"])) {
        echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">\n";
    }
    echo "<input type=hidden name=executar value=sim>\n";
    echo "<input type=hidden name=resp value=".@$resp.">\n";
    echo "<input type=hidden name=correcao value=".@$correcao.">\n";
    echo "<input type=hidden name=resp_it value=".@$resp_it.">\n";
    echo "<input type=hidden name=it value=".@$it.">\n";
    echo "<input type=hidden name=error value=".@$error.">\n";
    if ($opcao_execucao == 0) {
        echo "<input type=hidden name=deg value=".$deg.">\n";
        echo "<input type=hidden name=d value=".$d.">\n";
        for($i = 0; $i < $deg; $i++) {
            echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">\n";
        }
        echo "<input type=hidden name=coef[] value=".$coef[$deg].">\n";
        echo "<input type=hidden name=opcao_execucao value=0>\n";
    } // end if
    if ($opcao_execucao == 1) {
        echo "<input type=hidden name=funcao value=".$funcao.">\n";
        echo "<input type=hidden name=opcao_execucao value=1>\n";
    } // end if
    echo "<input class=button type=submit name=Submit value='".$msg->get('EQNL_MSG_03a')."'>\n";
    echo "</form>";
    // formulario para Metodo de Newton
    echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>\n";
    if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
        echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">\n";
        echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">\n";
        echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">\n";
    }
    if (isset($encontrouresp) && $encontrouresp == true) {
        echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"$respencontrada\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"$respiteracoes\">\n";
    }
    if (isset($_POST["respeqnl1"])) {
        echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">\n";
    }
    if (isset($_POST["respeqnl3"])) {
        echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">\n";
        echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">\n";
    }
    echo "<input type=hidden name=executar value=sim>\n";
    echo "<input type=hidden name=resp value=".@$resp.">\n";
    echo "<input type=hidden name=correcao value=".@$correcao.">\n";
    echo "<input type=hidden name=resp_it value=".@$resp_it.">\n";
    echo "<input type=hidden name=it value=".@$it.">\n";
    echo "<input type=hidden name=error value=".@$error.">\n";
    if ($opcao_execucao == 0) {
        echo "<input type=hidden name=deg value=".$deg.">\n";
        echo "<input type=hidden name=d value=".$d.">\n";
        for($i = 0; $i < $deg; $i++) {
            echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">\n";
        }
        echo "<input type=hidden name=coef[] value=".$coef[$deg].">\n";
        echo "<input type=hidden name=opcao_execucao value=0>\n";
    } // end if
    if ($opcao_execucao == 1) {
        echo "<input type=hidden name=funcao value=".$funcao.">\n";
        echo "<input type=hidden name=opcao_execucao value=1>\n";
    } // end if
    echo "<input class=button type=submit name=Submit value='".$msg->get('EQNL_MSG_03c')."'>\n";
    echo "</form>\n";
    echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>\n";
    echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">\n";
    echo "</form>";
    if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
        echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">\n";
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "function criarLinks(value) {\n";
        echo "document.exemplos.indice.value = value;\n";
        echo "document.exemplos.action = 'index.php?inc=eqnl2.php&modo=exemplo'\n";
        echo "document.exemplos.submit();\n";
        echo "}\n";
        echo "</script>\n";
        echo "<input type=\"hidden\" name=\"id_bib\" value=\"".@$id_bib."\">\n";
        echo "<input type=\"hidden\" name=\"xml_file\" value=\"".@$xml_file."\"\n";
        echo "<input type=\"hidden\" name=\"indice\">\n";
        echo "</form>\n";
        echo $msg->get('Outros_Exemplos').":<br>\n";
        $objeto = new DOMDocument();
        $objeto->load($xml_file);
    	$filho = $objeto->getelementsbytagname("rootfinding");
    	if ($filho->length > 0)
    	{
    		$tmp=0;
    		$equation = $filho->item(0)->getelementsbytagname("equation");
    		for ($i = 0; $i < $equation->length; $i++)
    		{
    			$temp=$equation->item($i)->getelementsbytagname("option");
    			$temp1=$temp->item(0)->getattribute("data");
    			if ($temp1 == 'polynom')
    			{
        			 $tmp++;
        			if ($i) echo " | ";
                    if ($i == $indice) echo "<b>";
                    echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
        			if ($i == $indice) echo "</b>";
    			}
    		}
    		for ($i = 0; $i < $equation->length; $i++)
    		{
    			$temp=$equation->item($i)->getelementsbytagname("option");
    			$temp1=$temp->item(0)->getattribute("data");
    			if ($temp1 == 'function')
    			{
        			$tmp++;
        			if ($i) echo " | ";
        			if ($i == $indice) echo "<b>";
        			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
        			if ($i == $indice) echo "</b>";
    			}
    		}
    	}
    }
}
?>
</div>